package rs.udd.model;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.envers.Audited;
import org.hibernate.validator.constraints.NotBlank;

@Audited
@Entity
@Table(name = "UDD_ADVERTISER_AGENT_CONTACT")
public class AdvertiserAgentContact extends AbstractEntity {

	private static final long serialVersionUID = 9043997569392530178L;

	@NotNull
	@ManyToOne
	@JoinColumn(name = "fkAdvertiserContacted", referencedColumnName = "id")
	private Advertiser advertiser;
	
	@NotNull
	@ManyToOne
	@JoinColumn(name = "fkAgentContacted", referencedColumnName = "id")
	private Agent agent;
	
	@NotBlank
	private String message;
	
	public AdvertiserAgentContact() {
		
	}

	public Agent getAgent() {
		return agent;
	}

	public void setAgent(Agent agent) {
		this.agent = agent;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Advertiser getAdvertiser() {
		return advertiser;
	}

	public void setAdvertiser(Advertiser advertiser) {
		this.advertiser = advertiser;
	}

	@Override
	public int hashCode() {

		return new HashCodeBuilder()
				.appendSuper(super.hashCode())
				.append(advertiser)
				.append(agent)
				.hashCode();
	}

	@Override
	public boolean equals(Object obj) {

		if (obj == null) {
			return false;
		}
		if (obj == this) {
			return true;
		}
		if (obj.getClass() != getClass()) {
			return false;
		}

		final AdvertiserAgentContact otherAdvertiserAgentContact = (AdvertiserAgentContact) obj;

		return new EqualsBuilder()
				.appendSuper(super.equals(obj))
				.append(advertiser, otherAdvertiserAgentContact.getAdvertiser())
				.append(agent, otherAdvertiserAgentContact.getAgent())
				.isEquals();
	}

	@Override
	public String toString() {

		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
				.append(super.toString())
				.append(message)
				.toString();
	}
	
}
